{extend name="main"}
{block name="style"}
<style type="text/css">
	.w-100px{width: 100px;}
</style>
{/block}
{block name="body"}
<div class="bg-white mb-3">
	<el-form :model="search" @submit.native.prevent="submitForm" ref="search" label-position="right" class="flex py-3">

	  <el-form-item label="用户ID" prop="uid" class="flex mb-0 pl-3">
	    <el-input v-model="search.uid" placeholder="用户ID" class="w-100px"></el-input>
	  </el-form-item>

	  <el-form-item label="应用" prop="app_id" class="flex mb-0 pl-3">
	    <el-input v-model="search.app_id" placeholder="APPID" class="w-100px"></el-input>
	  </el-form-item>

	  <el-form-item label="接口" prop="api_id" class="flex mb-0 pl-3">
	    <el-input v-model="search.api_id" placeholder="接口ID" class="w-100px"></el-input>
	  </el-form-item>

	  <el-form-item label="IP" prop="ip" class="flex mb-0 pl-3">
	    <el-input v-model="search.ip" placeholder="IP"></el-input>
	  </el-form-item>

	  <el-form-item label="时间" prop="time" class="flex mb-0 pl-3">
	  	<el-date-picker
	      v-model="search.time"
	      type="daterange"
	      align="left"
	      range-separator="至"
	      start-placeholder="开始日期"
	      end-placeholder="结束日期"
	      format="yyyy-M-d"
	      value-format="yyyy-M-d"
	      :picker-options="pickerOptions">
	    </el-date-picker>
	  </el-form-item>

	  <el-form-item class="flex mb-0 pl-3">
	    <el-button type="primary" @click="initHtml">查询</el-button>
	    <el-button @click="resetForm('search')">重置</el-button>
	  </el-form-item>
	</el-form>
</div>
<div class="bg-white p-3">
	<div class="table-responsive py-3">
		  <el-button type="primary" size="mini" @click="exportLoginLog">导出({{tableData.length}})</el-button>
	</div>
	<div class="table-responsive">
		<el-table
      	:data="tableData"
		v-loading="search.ajax"
		style="width: 100%;"
		header-cell-class-name="table-header-DDE6FB">
	    <el-table-column
	      prop="id"
	      label="ID"
	      width="100">
	    </el-table-column>
	    <el-table-column
	      prop="uid"
	      label="UID"
	      width="100">
	    </el-table-column>
	    <el-table-column
	      label="用户"
	      width="200">
	      <template slot-scope="scope">
	      	<div class="flex flex-center">
				<el-image
				  	v-if="scope.row.headimg" 
				    style="width: 30px; height: 30px"
				    lazy
				    class="rounded-circle mr-2"
				    :src="scope.row.headimg" 
				    :preview-src-list="[scope.row.headimg]">
				</el-image>
	      		<div>{{scope.row.nickname}}</div>
	      	</div>
	      </template>
	    </el-table-column>
	    <el-table-column
	      prop="app_name"
	      label="应用"
	      width="200">
	    </el-table-column>
	    <el-table-column
	      prop="devices_id"
	      label="设备ID">
	    </el-table-column>
	    <el-table-column
	      prop="ip"
	      label="IP"
	      width="160">
	    </el-table-column>
	    <el-table-column
	      prop="create_time"
	      label="访问时间"
	      width="240">
	    </el-table-column>
	    </el-table>
	</div>
	<div class="table-responsive py-3 text-center">
		<el-pagination
		  background
	      @size-change="handleSizeChange"
	      @current-change="handleCurrentChange"
	      :current-page="search.page"
	      :page-sizes="[10,50,100,200,500,1000]"
	      :page-size="search.pageSize"
	      layout="total, sizes, prev, pager, next, jumper"
	      :total="search.total">
	    </el-pagination>
	</div>
</div>
<el-dialog title="支付信息" :visible.sync="dialogTableVisible">
	<table class="table">
		<tr v-for="(v,index) in payInfo">
			<td width="180">{{index}}</td>
			<td>{{v}}</td>
		</tr>
	</table>
</el-dialog>
{/block}
{block name="script"}
<script type="text/javascript">
	{empty name="OrderType"}
	var OrderType=[];
	{else/}
	var OrderType={:json_encode($OrderType,JSON_UNESCAPED_UNICODE)};
	{/empty}
</script>
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			OrderType:OrderType,
			dialogTableVisible:false,
	        payInfo: {},
			labelPosition:'right',
	        pickerOptions: {
	          shortcuts: [{
	            text: '最近一周',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
	              picker.$emit('pick', [start, end]);
	            }
	          }, {
	            text: '最近一个月',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
	              picker.$emit('pick', [start, end]);
	            }
	          }, {
	            text: '最近三个月',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
	              picker.$emit('pick', [start, end]);
	            }
	          }, {
	            text: '最近半年',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
	              picker.$emit('pick', [start, end]);
	            }
	          }]
	      	},
			search:{
				uid:'{notempty name=":request()->get('uid')"}{:request()->get('uid')}{/notempty}',
				app_id:'',
				ip:'',
				time:[],
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
			resetForm:function(formName) {
				this.$refs[formName].resetFields();
			},
			handleSizeChange(val) {
				this.search.page=1;
				this.search.pageSize=val;
	          	this.initHtml();
			},
			handleCurrentChange(val) {
				this.search.page=val;
	          	this.initHtml();
			},
	      	initHtml() {
	      		var _this=this;
	      		_this.search.ajax=true;
				$.ajax({
					url:'',
					type:'get',
					data:_this.search,
					dataType:'json',
					error:function(err){
	      				_this.search.ajax=false;
						XYBase.error(XYBase.config.system_network_error);
					},
					success:function(ret){
	      				_this.search.ajax=false;
						if (ret) {
							if (ret.code === 0) {
								_this.search.total=ret.data.total;
								_this.tableData=ret.data.data;
							}else{
								XYBase.msg(ret.msg);
							}
						}else{
							XYBase.error(XYBase.config.system_network_error);
						}
					}
				});
			},
		    exportLoginLog() {
		    	var _this=this;
		    	_this.search.ajax=true;
		    	var loading=XYBase.openloading();
				$.ajax({
					url:'/user/exportLoginLog',
					type:'get',
					data:_this.search,
					dataType:'json',
					error:function(err){
			      		_this.search.ajax=false;
			      		loading.close();
						XYBase.error(XYBase.config.system_network_error);
					},
					success:function(ret){
			      		loading.close();
			      		_this.search.ajax=false;
						if (ret) {
							if (ret.code === 0) {
								window.open(ret.data.url);
							}else{
								XYBase.msg(ret.msg);
							}
						}else{
							XYBase.error(XYBase.config.system_network_error);
						}
					}
				});
			}
	    }
	});
	$(function(){
		vm.initHtml();
		reloadWindowSize();
		$(window).resize(function(){
			reloadWindowSize();
		});
	});
	function reloadWindowSize (argument) {
		var winW=$(window).width();
		if(winW <= 576){
			vm.labelPosition='top';
		}else{
			vm.labelPosition='right';
		}
	}
</script>
{/block}